package jdk8.functions;

import java.util.function.Predicate;

/**
 * 如果把所有判断条件的变量都放到一个对象里面，就可以交给Predicate处理
 */
public class DemoPredicate {
    public static void main(String[] args) {
        method(s -> s.length() > 5);

        method(s -> s.startsWith("H"), s -> s.length() > 5);
    }

    private static void method(Predicate<String> predicate) {
        boolean isLongerThan5 = predicate.test("HelloWorld");
        System.out.println("字符串长度大于5吗？ ： " + isLongerThan5);
    }


    private static void method(Predicate<String> one, Predicate<String> two){
        boolean testAnd = one.and(two).test("HelloWorld");
        System.out.println(testAnd);

        boolean testOr = one.or(two).test("Hello");
        System.out.println(testOr);

        boolean testNegate = one.negate().test("AelloWorld");
        System.out.println(testNegate);
    }


}
